<?php

namespace app\api\controller;

//use think\Db;
//use app\api\model\Log as api_visitor;
//use app\api\model\Common;
use app\data\Data;

class Log extends Index
{
//    public function visitor_list()
//    {
//        $VisitorLog = new api_visitor;
//        $result = $VisitorLog->visitor_list();
//        return jsonp($result);
//    }


//    public function admin_log_list()
//    {
//        $number = 10;
//        $page = 1;
//        $page = !empty(input("post.curr")) ? input("post.curr") : $page;
//        if (!empty(input("post.content"))) {
//            $where['username|email|phone'] = ["like", input("post.search")];
//        }
//        $logmin = !empty(input("post.logmin")) ? strtotime(input("post.logmin")) : 0;
//        $logmax = !empty(input("post.logmax")) ? strtotime(input("post.logmax") . " 23:59:59") : time();
//        $where['time'] = ['between', [$logmin, $logmax]];
//
//        $info_count = Db::connect("db_mongo")->name("admin_log")->where($where)->count();
//        $pages = ceil($info_count / $number);
//        $info = Db::connect("db_mongo")->name("admin_log")->where($where)->order('time', 'desc')->page($page, $number)->select();
//        $result['pages'] = $pages;
//        $result['info'] = $info;
//        return jsonp($result);
//    }

    public function ment_list()
    {
        $page = (isset($_GET['page']) && !empty($_GET['page'])) ? $_GET['page'] : 1;
        $username = (isset($_GET['username']) && !empty($_GET['username']) ? $_GET['username'] : null);
        $logmin = (isset($_GET['logmin']) && $_GET['logmin']) ? strtotime($_GET['logmin']) : 0;
        $logmax = (isset($_GET['logmax']) && $_GET['logmax']) ? (strtotime($_GET['logmax']) + 24 * 60 * 60 - 1) : time();


        $where['time'] = array(array('egt', $logmin), array('elt', $logmax), 'and');
        $where['name'] = array('like', "%$username%");
        $zgh_orders = new Data('log_ment');
        $res['data'] = $zgh_orders->selectPage($page, $where);
        $res['count'] = $zgh_orders->count($where);
        if (isset($res) || empty($res)) {
            $this->_jsonp('200', '会员日志信息查询成功', $res);
        } else {
            $this->_jsonp('1000', '会员日志信息查询失败', null);
        }
    }

    public function admin_list()
    {
        $page = (isset($_GET['page']) && !empty($_GET['page'])) ? $_GET['page'] : 1;
        $username = (isset($_GET['username']) && !empty($_GET['username']) ? $_GET['username'] : null);
        $logmin = (isset($_GET['logmin']) && $_GET['logmin']) ? strtotime($_GET['logmin']) : 0;
        $logmax = (isset($_GET['logmax']) && $_GET['logmax']) ? (strtotime($_GET['logmax']) + 24 * 60 * 60 - 1) : time();


        $where['time'] = array(array('egt', $logmin), array('elt', $logmax), 'and');
        $where['name'] = array('like', "%$username%");
        $zgh_orders = new Data('log_admin');
        $res['data'] = $zgh_orders->selectPage($page, $where);
        $res['count'] = $zgh_orders->count($where);
        if (isset($res) || empty($res)) {
            $this->_jsonp('200', '管理员日志信息查询成功', $res);
        } else {
            $this->_jsonp('1000', '管理员日志信息查询失败', null);
        }
    }

    public function visitor_list()
    {
        $page = (isset($_GET['page']) && !empty($_GET['page'])) ? $_GET['page'] : 1;
        $username = (isset($_GET['username']) && !empty($_GET['username']) ? $_GET['username'] : null);
        $logmin = (isset($_GET['logmin']) && $_GET['logmin']) ? strtotime($_GET['logmin']) : 0;
        $logmax = (isset($_GET['logmax']) && $_GET['logmax']) ? (strtotime($_GET['logmax']) + 24 * 60 * 60 - 1) : time();


        $where['time'] = array(array('egt', $logmin), array('elt', $logmax), 'and');
        $where['ip|os|browser|baseUrl'] = array('like', "%$username%");
        $zgh_orders = new Data('log_visitor');
        $field = "ip,time,os,browser,baseUrl,id";
        $res['data'] = $zgh_orders->selectPage($page, $where, $field);
        $res['count'] = $zgh_orders->count($where);
        if (isset($res) || empty($res)) {
            $this->_jsonp('200', '游客日志信息查询成功', $res);
        } else {
            $this->_jsonp('1000', '游客日志信息查询失败', null);
        }
    }

}
